<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<c:set var="ctx" value=" ${pageContext.request.contextPath}" />
<html>
<head>
<title>整改反馈管理</title>
	<script
	src="${ctx}/static/selectWin/auditProDtlSelector.js?version=${applicationScope.jsVersion }" type="text/javascript"></script>
<script type="text/javascript">
	var $grid;
	var grid;

	$(function() {
		$grid = $("#grid").datagrid($.extend({},datagridOption, {
			url : "${ctx}/fnd/problemRectify/dataGrid",
			fitColumns : true,
		    columns : [ [  {
				field : 'ck',
				checkbox : true
			}   , {
				field : 'auditProDtl.auditPro.auditName',
				title : '审计',
				width : 50,
				sortable : true
			}, {
				field : 'reportNumber',
				title : '审计报告页码',
				width : 50,
				sortable : true
			}   , {
				field : 'problemDescription',
				title : '问题描述',
				width :  120,
				sortable : true
			} , {
				field : 'auditSuggestion',
				title : '审计建议',
				width : 400,
				sortable : true
			} , {
				field : 'attachmentMaster.id',
				title : '附件',
				sortable : true,
				formatter : function(value, row, index) {
					return "<button id=\"attach\" type=\"button\" class=\"btn btn-primary\" onclick=\"fn_attachClick('"+value+"')\"><span class=\"glyphicon glyphicon-pencil\"></span> 附件</button>";
				}  
			}] ],
		}));
		
		$grid.datagrid('enableFilter', [ buildDGFilterYesOrNoFieldOptions($grid, 'enable') ]);
		$grid.datagrid('enableFilter', [ {
			field : 'auditProDtl',
			searchField : 'auditProDtl.auditPro.auditName'
		}]);
	     $auditProDtlSelector = $("#auditProDtl").comboselector(auditProDtlSelectOpts);
		$auditProDtlSelector=$("#auditProDtl").comboselector($.extend(auditProDtlSelectOpts,{
			onAfterEnter : function(val) {
					val.auditPro
					&& $("#auditProDtl").comboselector("setValue", val.id)
							.comboselector("setText", val.auditPro.auditName);
			}
		}));
		
		
	     $("#add").click(function() {
			$("#fm").form("clear");
			 
			$('#fm').form('load', {
				enable : 1
			});
			$("#dlg").dialog("open").dialog("setTitle", "新增整改反馈");
		});
		$("#edit").click(function() {
			var rowData = $grid.datagrid("getSelected");
			if (!rowData) {
				showInfo("您未选中行，无法编辑");
			} else {
				fn_edit(rowData);
			}
		});
		
		//excel导入
		$("#excelImport").click(function() {
			$.easyui.importor.showImportor({
				importNo : "problemRectify",
				onExportSuccess : function(file, data) {
					$grid.datagrid('load');
				}
			});
		});
		
		$("#delete").click(function() {
			multiDeleteDataGrid($grid, "${ctx}/fnd/problemRectify/multiDelete");
		});
		$("#search").click(function() {
			$grid.datagrid('load', $("#tt").form("getData"));
		});
		$("#excelExport").click(function() {
			var url = "${ctx}/fnd/problemRectify/excelExport?" + $.param($grid.datagrid('options').queryParams);
			if ($grid.datagrid("options").filterRules) {
				url += "&filterRules=" + JSON.stringify($grid.datagrid("options").filterRules);
			}
			window.parent.location.href = url;
		});
		 
	});
	 
	function fn_edit(rowData) {
		$("#dlg").dialog("open").dialog("setTitle", "编辑整改反馈");
		$("#fm").form("clear");
		$("#fm").form("load", rowData);
		  
		  rowData.auditProDtl
			&& $("#auditProDtl").comboselector("setValue",
					rowData.auditProDtl.id).comboselector("setText",
					rowData.auditProDtl.auditPro.auditName); 
		 
	}
 
	//打印功能的实现
	<shiro:hasPermission name="company:print">
	   function fun_print()
	   {
		   printDataGrid($grid, "${ctx}/fnd/problemRectify/print?ids=");
	   }
	   function printDataGrid($grid, printUrl, operName) {
			var rows = $grid.datagrid('getChecked');
			var ids = "";
			if (rows) {
				$.each(rows, function(index, value) {
					ids += (value.id + ",")
				});
				if (ids == "") {
					$.messager.alert("操作提醒", "请先勾选需要打印的记录", "warning");
				} else {
					$.messager.confirm("您确定要打印勾选的" + rows.length + "条记录吗？", function(c) {
						if (c) {
							window.open(printUrl+ids, "_blank");//重新打开 
						}
					});
				}
			} else {
				$.messager.alert("操作提醒", "请先勾选需要打印的记录", "warning");
			}
		}
	   </shiro:hasPermission>
	   
	 //-----------------------------附件-----------------------------------------------//		
		function fn_attachClick(id){
		  
			grid&&grid.datagrid('loadData',{total:0,rows:[]});
			grid = $("#grid_attach").datagrid({
				title : "附件",
				fitColumns : true,
				method : "get",
				singleSelect : true,
				pagination : true,
				url : "${ctx}/basic/attachment/dataGrid/"+id
			});
			
			
		 
				$("#dlg_attach").dialog("open").dialog("setTitle", "编辑附件");
				$('#file_upload').show();
				$('#file_upload').uploadify({
			        'swf'      : '${ctx}/static/uploadify/uploadify.swf',
			        'uploader' : kl.ctx +'/basic/attachment/busUpload/'+id+';JSESSIONID=<%=session.getId()%>',
			        'buttonText':'附件上传', 
			        'width':100,
			        'height':20,
			        'fileTypeDesc':'请选择doc xls jpg rar格式的文件',
					'fileTypeExts':fileTypeExts,//允许的格式
			         onUploadSuccess : function(file, data, response) {
			        	var data = eval('(' + data + ')');
			        	if(data.success){
			        		grid.datagrid("reload");
			        	}
			        	showInfo(data.msg);
			        }
			    }); 
			 
		}
		
		function fn_attach_formatter(value, row, index) {
			var rowData = $grid.datagrid('getSelected');
			var button="";
			 button=fmt_attach(value, row, index);
			 return button;
		}
	
</script>
</head>

<body>
	<div data-options="region:'center',fit:true,border:false">
		<table id="grid">
		</table>
	</div>
	<div id="tt" class="row">
		 
		<div class="col-md-8">
			<shiro:hasPermission name="problemRectify:update">
				<button id="add" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-plus"></span> 新增
				</button>
				<button id="edit" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-pencil"></span> 编辑
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="problemRectify:delete">
				<button id="delete" type="button" class="btn btn-danger">
					<span class="glyphicon glyphicon-minus"></span> 删除
				</button>
			</shiro:hasPermission>
			<shiro:hasPermission name="problemRectify:export">
				<button id="excelExport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-open"></span> Excel导出
				</button>
			</shiro:hasPermission>

			<%-- <shiro:hasPermission name="problemRectify:update">
				<button id="excelImport" type="button" class="btn btn-primary">
					<span class="glyphicon glyphicon-save"></span> Excel导入
				</button>
			</shiro:hasPermission> --%>
			 
		</div>
	</div>
	<shiro:hasPermission name="problemRectify:update">
	
	<div id="dlg" class="easyui-dialog" style="width: 620px; height: 540px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
				<input type="hidden" name="id" />  
				<table id="tbl">
						<tr>
						      <td><label>审计:</label></td>
							  <td><input id="auditProDtl" name="auditProDtl" class="easyui-textbox easyui-validatebox" data-options=" "></td>
						
								<td><label>审计报告页码:</label></td>
								<td ><input name="reportNumber" class="easyui-validatebox" data-options="required: true"></td>
							</tr>
							 
							 <tr>
								<td><label>问题描述:</label></td>
							    <td colspan="3"><input name="problemDescription" class="easyui-textbox" data-options="multiline:true,width:460,height:180,validType:'length[0,190]'"></td>
							</tr>
							<tr>
								<td><label>审计建议:</label></td>
							    <td colspan="3"><input name="auditSuggestion" class="easyui-textbox" data-options="multiline:true,width:460,height:180,validType:'length[0,190]'"></td>
							</tr>
				</table>
			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary"
					onclick="formSave('#fm', '#grid', '#dlg', '${ctx}/fnd/problemRectify/update');">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onClick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div>
		
		
		
		<%-- <div id="dlg" class="easyui-dialog" style="width: 680px; height: 540px; padding: 10px 20px"
			data-options="resizable:true,modal:true, buttons:'#dlg-btn',closed:true">
			<form id="fm" method="post">
		       <input type="hidden" name="id" />   
				<table id="tbl">
							 
							<tr>
								<td><label>审计:</label></td>
								<td><input id="auditProDtl" name="auditProDtl" class="easyui-textbox easyui-validatebox"  data-options="required: true"></td>

								<td><label>审计报告页码:</label></td>
								<td ><input name="reportNumber" class="easyui-validatebox" data-options="required: true"></td>
							</tr>
							 
							 <tr>
								<td><label>问题描述:</label></td>
							    <td colspan="3"><input name="problemDescription" class="easyui-textbox" data-options="multiline:true,width:460,height:180,validType:'length[0,190]'"></td>
							</tr>
							<tr>
								<td><label>审计建议:</label></td>
							    <td colspan="3"><input name="auditSuggestion" class="easyui-textbox" data-options="multiline:true,width:460,height:180,validType:'length[0,190]'"></td>
							</tr>
					 
					 
				</table>
			</form>
			<div id="dlg-btn">
				<button id="add" type="button" class="btn btn-primary" onclick="formSave('#fm', '#grid', '#dlg', '${ctx}/fnd/problemRectify/update');">
					<span class="glyphicon glyphicon-ok"></span> 保存
				</button>
				<button id="edit" type="button" class="btn btn-primary" onclick="$('#dlg').dialog('close');">
					<span class="glyphicon glyphicon-remove"></span> 取消
				</button>
			</div>
		</div> --%>

	
	
		<div id="dlg_attach" class="easyui-dialog"
			style=" padding: 10px 20px"
			data-options="resizable:true,modal:true,closed:true,fit:true">
			<div  class="easyui-layout" data-options="fit:true">   
				<div data-options="region:'center',border:false">
					<table id="grid_attach" data-options="fit:true">
						<thead>
							<tr>
								<th field="id" hidden="true"></th>
								<th field="fileName" width="160">文件名称</th>
								<th field="fileSize" width="60">大小</th>
								<th field="uploadTime" width="60">上传时间</th>
								<th field="operate" width="60" data-options="formatter:fn_attach_formatter"  >操作</th>
							</tr>
						</thead>
					</table>
				</div>
				<div data-options="region:'south'" style="height:150px">
					<div class="easyui-panel" title="附件上传" fit="true">
						<input type="file" name="file_upload" id="file_upload" />
					</div>
				</div>
			</div>
		</div>
		
	</shiro:hasPermission>
</body>
</html>
